package com.kfm.servlet;

import com.wf.captcha.GifCaptcha;
import com.wf.captcha.utils.CaptchaUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/captcha")
public class CaptchaServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        GifCaptcha captcha = new GifCaptcha(130, 48);
        System.out.println(captcha.text());
//        Cookie cookie = new Cookie("captcha", captcha.text());
//        resp.addCookie(cookie);

        // 存入session
//        req.getSession().setAttribute(Constant.CAPTCHA_ATTR, captcha.text());
//        captcha.out(resp.getOutputStream());

        CaptchaUtil.out(captcha, req, resp);
    }
}
